package com.xuzimian.globaldemo.spring.core.aop.test;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class AspectNoArgNames {


    @Pointcut(value = "execution(* com.xuzimian.globaldemo.spring.core.aop.test.*.*(..))")
    public void pointCut() {
        System.out.println("AOP pointCut 做了些什么？");
    }

    @Before(value = "pointCut()")
    public void doBefore(JoinPoint joinPoint) {
        System.out.println("AOP Before Advice... " + joinPoint.getArgs().length);
    }

    @After(value = "pointCut()")
    public void doAfter(JoinPoint joinPoint) {
        System.out.println("AOP After Advice... " + joinPoint.getArgs());
    }

    @AfterReturning(pointcut = "pointCut()", returning = "returnVal")
    public void afterReturn(JoinPoint joinPoint, Object returnVal) {
        System.out.println("AOP AfterReturning Advice:" + returnVal);
    }

    @AfterThrowing(pointcut = "pointCut()", throwing = "error")
    public void afterThrowing(JoinPoint joinPoint, Throwable error) {
        System.out.println("AOP AfterThrowing Advice..." + error);
        System.out.println("AfterThrowing... ");
    }

    @Around(value = "pointCut()")
    public void around(ProceedingJoinPoint pjp) {
        System.out.println("AOP Aronud before...");
        try {
            pjp.proceed();
        } catch (Throwable e) {
            e.printStackTrace();
        }
        System.out.println("AOP Aronud after...");
    }

}
